/*
 *  $TEAM_NAME Space Trader
 */

import models.Ship;
import models.StarSystem;
import models.TechLevel;
import models.Shipyard;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;

import org.junit.Test;

/**
 * Tests the Shipyard's canBuy method.
 * 
 * @author Jason Malia
 * @version 1.00
 */

public class ShipyardBuyTest {
	/**
	 * Sets a timeout limit
	 */
	private static final int TIMEOUT = 1000;
	
	/**
	 * Test that the correct ships are available for purchase.
	 */
	
	@Test(timeout = TIMEOUT)
	public void testShipyardBuy1(){
		final Ship myShip = Ship.flea();
		final Ship gnat = Ship.gnat();
		final Ship firefly = Ship.fireFly();
		final Ship mosquito = Ship.mosquito();
		final Ship bumblebee = Ship.bumblebee();
		
		final StarSystem currentLocation = StarSystem.randomStarSystemWithName("Earth");
		currentLocation.setTechLevel(TechLevel.AGRICULTURE);
		
		final Shipyard shipyard = new Shipyard(currentLocation);
		
		assertTrue("Can't buy a ship even though min tech level is met.",
				 shipyard.canBuy(myShip, gnat));
		assertFalse("Can buy a ship even though min tech level is not met.",
				 shipyard.canBuy(myShip, firefly));
		assertFalse("Can buy a ship even though min tech level is not met.",
				 shipyard.canBuy(myShip, mosquito));
		assertFalse("Can buy a ship even though min tech level is not met.",
				 shipyard.canBuy(myShip, bumblebee));
	}
	
	/**
	 * Test to make sure you can't buy a ship you 
	 * just bought, and that you can buy a ship you just replaced.
	 */
	@Test(timeout = TIMEOUT)
	public void testShipyardBuy2(){
		final Ship myShip = Ship.flea();
		final Ship newShip = Ship.bumblebee();
		
		final StarSystem currentLocation = StarSystem.randomStarSystemWithName
				("Death Star");
		currentLocation.setTechLevel(TechLevel.HI_TECH);
		
		final Shipyard shipyard = new Shipyard(currentLocation);
		
		assertTrue("Can't buy a ship even though min tech level is met.",
				shipyard.canBuy(myShip, newShip));
		
		//Now the new ship has been bought, so it shouldn't be available and the old ship should be.
		assertFalse("Can buy a ship you just bought.",
				 shipyard.canBuy(myShip, newShip));
		assertTrue("Can't but a ship you just replaced.",
				shipyard.canBuy(newShip, myShip));
	}
	
}
